﻿using System;
using System.Collections;
using System.Configuration.Install;

namespace Altairis.Web.Configuration.Encryption.Install {
    public  class AssemblyGacInstaller : Installer {

        public override void Install(IDictionary stateSaver) {
            // Base install task
            base.Install(stateSaver);

            // Install current assembly to GAC
            try {
                Console.Write("Installing assembly to GAC...");
                var mya = System.Reflection.Assembly.GetExecutingAssembly();
                var p = new System.EnterpriseServices.Internal.Publish();
                p.GacInstall(mya.Location);
                Console.WriteLine("OK");
            }
            catch (Exception ex) {
                Console.WriteLine("Failed!");
                Console.WriteLine(ex.ToString());
            }
        }

        public override void Uninstall(IDictionary savedState) {
            // Base uninstall task
            base.Uninstall(savedState);

            // Remove current assembly from GAC
            try {
                Console.Write("Removing assembly from GAC...");
                var mya = System.Reflection.Assembly.GetExecutingAssembly();
                var p = new System.EnterpriseServices.Internal.Publish();
                p.GacRemove(mya.Location);
                Console.WriteLine("OK");
            }
            catch (Exception ex) {
                Console.WriteLine("Failed!");
                Console.WriteLine(ex.ToString());
            }
        }

    }
}
